package org.example;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class test12 {

    public static void main(String[] args) {
        //将乱序的出师表按照顺序进行输出排序然后储存

        try (
                BufferedReader br = new BufferedReader(new FileReader("src/week-4/src/main/resources/test2.txt"));
                BufferedWriter bw = new BufferedWriter(new FileWriter("src/week-4/src/main/resources/test3.txt"));
        ) {

            //1.定义一个ArryList集合储存每段内容
            List<String> data = new ArrayList<>();
            System.out.println("hello");

            //2.定义一个循环，按照行读取文章
            String line;
            while ((line = br.readLine()) != null) {
                data.add(line);
            }

            //3.对文章进行排序
            //(???)
            Collections.sort(data);
            System.out.println(data);

            //4.遍历Liist集合的每段内容，依次写出到新文件中
            for (String ln :
                    data) {
                bw.write(ln);
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}


